package cn.tedu._02notice.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    //内部状态码，提示消息，具体数据
    private Integer state;
    private String message;
    private Object data;

    /**
     * 没有具体数据返回的控制器方法
     */
    public JsonResult(StatusCode statusCode){
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
    }

    /**
     * 2.针对于具有具体数据返回的控制器方法
     */
    public JsonResult(StatusCode statusCode,Object data){
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
        this.data=data;
    }

    /**
     * 3.封装两个静态方法：只对于操作成功的场景;
     * 3.1
     */

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }







}
